var a = getApp();

Page({
    data: {
        language: "",
        goodsList: [],
        type: "",
        searchVal: "",
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        navStatus: "",
        priceBol: !0,
        salesBol: !0
    },
    onLoad: function(a) {
        var t = a.goods_type;
        this.setData({
            type: t
        }), this._getData(), "is_recommand" == t ? wx.setNavigationBarTitle({
            title: "精选推荐课程"
        }) : "is_hot" == t ? wx.setNavigationBarTitle({
            title: "精选热卖课程"
        }) : wx.setNavigationBarTitle({
            title: "精选推荐课程"
        });
    },
    back: function() {
        wx.navigateBack();
    },
    onReady: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    _getData: function() {
        var t = this;
        this.data.page = 1, a._getNetWork({
            url: a.getNetAddresss("plugin.video-demand.api.video-course-goods.get-course-goods&page=1"),
            data: {
                goods_type: t.data.type,
                search: t.data.searchVal,
                filter_order: t.data.navStatus,
                page: t.data.page
            },
            success: function(e) {
                if (1 != e.data.result || a._isTextEmpty(e.data.data)) console.error(e); else {
                    var s = e.data.data;
                    t.setData({
                        total_page: s.last_page,
                        goodsList: s.data
                    });
                }
            },
            fail: function(a) {
                console.error(a);
            }
        });
    },
    _getMoreData: function() {
        var t = this, e = a.getNetAddresss("plugin.video-demand.api.video-course-goods.get-course-goods");
        this.data.page >= this.data.total_page ? t.setData({
            isLoadMore: !1
        }) : (t.setData({
            page: this.data.page + 1
        }), a._getNetWork({
            url: e,
            data: {
                page: t.data.page,
                goods_type: t.data.type,
                search: t.data.searchVal,
                filter_order: t.data.navStatus
            },
            success: function(a) {
                if (1 == a.data.result) {
                    var e = a.data.data;
                    t.setData({
                        isLoadMore: !0,
                        goodsList: t.data.goodsList.concat(e.data)
                    });
                } else t.setData({
                    page: t.data.page - 1,
                    isLoadMore: !1
                });
            },
            fail: function(a) {
                console.log(a);
            }
        }));
    },
    getDataBth: function(a) {
        var t = a.currentTarget.dataset.type, e = this.data.salesBol, s = this.data.priceBol;
        console.log(t), t ? "sales" == t ? (this.setData({
            priceBol: !0
        }), e ? this.setData({
            salesBol: !1,
            navStatus: "sales_asc"
        }) : this.setData({
            salesBol: !0,
            navStatus: "sales_desc"
        })) : "price" == t && (this.setData({
            salesBol: !0
        }), s ? this.setData({
            priceBol: !1,
            navStatus: "price_asc"
        }) : this.setData({
            priceBol: !0,
            navStatus: "price_desc"
        })) : this.setData({
            salesBol: !0,
            priceBol: !0,
            navStatus: ""
        }), this.setData({
            page: 1,
            total_page: 0,
            isLoadMore: !0,
            goodsList: []
        }), this._getData();
    },
    bindKeyInput: function(a) {
        this.setData({
            searchVal: a.detail.value
        });
    },
    toCourse: function(a) {
        var t = a.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + t
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.setData({
            isLoadMore: !0,
            page: 1,
            total_page: 0
        }), this._getData();
    },
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData() : (console.log("没有更多数据"), wx.showToast({
            title: "没有更多数据",
            icon: "none",
            duration: 1e3
        }));
    },
    onShareAppMessage: function() {}
});